package com.enation.app.javashop.api.client;

import com.enation.app.javashop.client.trade.OrderMetaClient;
import com.enation.app.javashop.model.promotion.fulldiscount.dos.FullDiscountGiftDO;
import com.enation.app.javashop.model.trade.order.dos.OrderMetaDO;
import com.enation.app.javashop.model.trade.order.enums.OrderMetaKeyEnum;
import com.enation.app.javashop.service.trade.order.OrderMetaManager;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 订单OrderMeta相关API
 *
 * @author fk
 * 2020.4.16
 * @version v2.0
 * @since v7.2.0
 */
@Api(description = "订单相关API")
@RestController
@RequestMapping("/client/orders")
@Validated
@ApiIgnore
public class OrderMetaClientController{

    @Autowired
    private OrderMetaManager orderMetaManager;

    @RequestMapping(value = "/order-meta", method = RequestMethod.POST)
    public void add(@RequestBody OrderMetaDO orderMetaDO) {
        orderMetaManager.add(orderMetaDO);
    }

    @RequestMapping(value = "/{order_sn}/order-meta/gift-list", method = RequestMethod.GET)
    public List<FullDiscountGiftDO> getGiftList(@PathVariable("order_sn") String orderSn, @RequestParam("status") String status) {
        return orderMetaManager.getGiftList(orderSn, status);
    }

    @PutMapping("/{order_sn}/order-meta/status")
    public void updateMetaStatus(@PathVariable("order_sn") String orderSn,@RequestParam("meta_key")  OrderMetaKeyEnum metaKey,  @RequestParam("status") String status) {
        orderMetaManager.updateMetaStatus(orderSn, metaKey, status);
    }

    @GetMapping("/{order_sn}/meta-value")
    public String getMetaValue(@PathVariable("order_sn")String orderSn, @RequestParam("meta_key")OrderMetaKeyEnum metaKey) {
        return orderMetaManager.getMetaValue(orderSn, metaKey);
    }
}
